
from pptx import Presentation
from pptx.dml.color import RGBColor
from pptx.enum.shapes import MSO_SHAPE_TYPE

def set_font_black(text_frame):
    """设置文本框中所有文字颜色为黑色"""
    for paragraph in text_frame.paragraphs:
        for run in paragraph.runs:
            run.font.color.rgb = RGBColor(0, 0, 0)

def process_ppt(input_path, output_path):
    prs = Presentation(input_path)

    for slide in prs.slides:
        # 先收集要删除的图片形状
        shapes_to_delete = []

        for shape in slide.shapes:
            # 删除所有图片形状（可能是背景图）
            if shape.shape_type == MSO_SHAPE_TYPE.PICTURE:
                shapes_to_delete.append(shape)

            # 设置字体为黑色
            if shape.has_text_frame:
                set_font_black(shape.text_frame)

        # 删除收集的图片形状
        for shape in shapes_to_delete:
            sp = shape._element
            sp.getparent().remove(sp)

    prs.save(output_path)
    print(f"处理完成，保存为：{output_path}")

# 使用示例
input_ppt = 'C:\\Users\\gx_st\\Desktop\\汇川驱动器控制器\\01-第一章-第一节-企业与企业财务管理.pptx'        # 替换为你的文件路径
output_ppt = 'C:\\Users\\gx_st\\Desktop\\汇川驱动器控制器\\01-第一章-第一节-企业与企业财务管理1.pptx'
process_ppt(input_ppt, output_ppt)
